package file_util

import (
	"io/fs"
	"os"
)

// 本地文件系统
type LocalFS struct {
	// 基本路径
	_BasePath string
}

func NewLocalFS(basePath string) *LocalFS {
	localFS := LocalFS{_BasePath: basePath}

	return &localFS
}

func (_fs *LocalFS) Open(name string) (fs.File, error) {
	realPath := JoinPath(_fs._BasePath, name)

	return os.Open(realPath)
}

func (_fs *LocalFS) ReadFile(name string) ([]byte, error) {
	realPath := JoinPath(_fs._BasePath, name)

	return os.ReadFile(realPath)
}

func (_fs *LocalFS) ReadDir(name string) ([]fs.DirEntry, error) {
	realPath := JoinPath(_fs._BasePath, name)

	return os.ReadDir(realPath)
}
